using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

public class Lift : MonoBehaviour
{
    private bool playerInrange;
    [SerializeField] private GameObject SwitchUI;
    [SerializeField] private float delayTime;

    void Start()
    {
        SwitchUI.SetActive(false);
    }
    private void Update()
    {
        if(playerInrange&&Input.GetKeyDown(KeyCode.E))
        {
            StartCoroutine(SwitchScene());
        }
    }
    void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision.CompareTag("Player"))
        {
            playerInrange = true;
        }
        SwitchUI.SetActive(true);

    }
    void OnTriggerExit2D(Collider2D collision)
    {
        if (collision.CompareTag("Player"))
        {
            playerInrange = false;
        }
        SwitchUI.SetActive(false);
    }
    IEnumerator SwitchScene()
    {
        yield return new WaitForSeconds(delayTime);
        SceneManager.LoadSceneAsync("Stage2");
    }
}
